using System;
using Sce.PlayStation.Core;

namespace Nyanimals
{
	public class CPlayerWhistleState : CPlayerBaseState
	{
        private bool whistled;
		public CPlayerWhistleState(string szName, CPlayer pl) : base(szName, pl)
		{
		}

		public override void Enter ()
		{
			player.ChangeAnimation("whistle");
			// Console.WriteLine("PlayerWhistleState::Enter()");
            
            whistled = false;
		}

		public override void Exit ()
		{
			// Console.WriteLine("PlayerWhistleState::Exit()");
		}
        
        public override void Input ()
		{
			CInput input = CInput.Instance;			
		}     
		public override void Update (float deltaTime)
		{
			if(player.Context.Playing == false)
			{
				owningMachine.ChangeState("idle");
                
                // whistle event just in case we somehow missed the frame(bad fps)
                Whistle();
			}
            
            // if after a certain frame
            if(false /* TODO: after whistle frame */)
            {
                Whistle();
            }
            
            // no movement
			player.Velocity = Vector3.Zero;
			player.LeftStick = Vector2.Zero;
		}
        
        private void Whistle()
        {
            if(whistled == false)
            {
                CWhistleEvent e = new CWhistleEvent(player.Position);
                CEventManager.Instance.QueueEvent(e);
                player.WhistleSphereUpdate();
                whistled = true;
            }
        }
	}
}

